<?php

namespace Ipartek\BlogBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class PersistenciaControllerTest extends WebTestCase
{
	/** @test */
    public function testWellcomePage()
    {
        $client = static::createClient();

        //SUT
        $client->request('GET', '/');

        $this->assertEquals(200, $client->getResponse()->getStatusCode(),
            'La portada se genera correctamente.'
        );
    }
    
    /** @test */
    public function testWelcomePageLoadTime()
    {
        $client = static::createClient();
        $client->request('GET', '/');

        if ($profiler = $client->getProfile()) {
            // 500 es el tiempo en milisegundos
            $this->assertLessThan(500, $profiler->getCollector('time')->getTotalTime(),
                'La portada se genera en menos de medio segundo'
            );
        }
    }
    
    /** @test */
    public function testUrlDetalleNoticia()
    {
    	$client = static::createClient();
    	$url=$client->getContainer()->get('router')->generate('persistencia_detalle',
array('slug' => 'toyota-lanza-el-yaris-soho'));
    	$client->request('GET', $url);

        $this->assertEquals(200, $client->getResponse()->getStatusCode(),
            'La url detalle noticia se genera correctamente'
        );
    }
    
    /** @test */
    public function testTodasNoticias()
    {
    	$em = $this->getDoctrine()->getManager();
    	$noticias = $em->getRepository('IpartekBlogBundle:Noticia')->findAll();
    	
    	foreach ($noticias as $noticia){
    	}
    	
    	$client = static::createClient();
    	$url=$client->getContainer()->get('router')->generate('persistencia_detalle',
    			array('slug' => 'toyota-lanza-el-yaris-soho'));
    	$client->request('GET', $url);
    
    	$this->assertEquals(200, $client->getResponse()->getStatusCode(),
    			'La url detalle noticia se genera correctamente'
    	);
    }
}
